import 'package:flutter/material.dart';
import 'package:rxdart/rxdart.dart';
import 'package:schoollifedemo/base/common_function.dart';
import 'package:schoollifedemo/base/url_contract.dart';
import 'package:schoollifedemo/commonwidget/common_base_viewmodel.dart';
import 'package:schoollifedemo/entity/Entity.dart';

class AnnouncementDetailPageViewModel extends BaseViewModel {
  SchoolAnnouncementDetailResponse? _schoolAnnouncementDetailResponse;

  SchoolAnnouncementDetailResponse? get schoolAnnouncementDetailResp =>
      _schoolAnnouncementDetailResponse;

  PublishSubject loadingState = PublishSubject<CommonLoadingState?>();

  Future<void> pullWebUrl({
    required String url,
    OnSuccess? onSuccess,
    OnFailure? onFailure,
  }) async {
    final params = <String, Object?>{};
    params['account'] = getApplication().getLoginAccount();
    params['base64_url'] =
        await getChannelService().getCommonChannelFunc()?.encodeBase64(url);
    final result = await getNetworkUtil()
        .postHttp(UrlContract.pullDetailNewsWebUrl, params: params);
    final resp = SchoolAnnouncementDetailResponse.fromMap(result);
    if (resp.status == 0) {
      _schoolAnnouncementDetailResponse = resp;
      loadingState.add(CommonLoadingState.successTypeOne);
      if (onSuccess != null) {
        onSuccess();
      }
    } else {
      if (onFailure != null) {
        onFailure(resp.msg);
      }
    }
  }

  Future<void> backPage(BuildContext context) async {
    return getApplication().routerPop(context);
  }
}
